package cn.edu.scau.cmi.linpeiwei.controller;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;

import javafx.scene.text.Text;

import javafx.scene.control.TextField;

import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.linpeiwei.abstractFactory.domainAbstractClass.AutoInsurance;
import cn.edu.scau.cmi.linpeiwei.abstractFactory.factory.AbstractFactory;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.control.ChoiceBox;

public class AbstractFactoryController extends AnchorPane implements Initializable{
	@FXML
	private ChoiceBox choiceBox1;
	@FXML
	private Button infoButton;
	@FXML
	private ImageView imageView;
	@FXML
	private TextField textFieldName;
	@FXML
	private TextField textFieldNum;
	@FXML
	private Text textInfo;
	@FXML
	private ChoiceBox choiceBox2;
	private Image image;
	private String[] company= {"PICC","PingAn"};
	private String[] insurance = {"驾驶员身体受伤", "汽车损坏", "人员伤亡", "多种事故"};
	private AbstractFactory abstractFactory;
	private AutoInsurance autoInsurance;

	// Event Listener on Button[#infoButton].onAction
	@FXML
	public void eventButton(ActionEvent event) {
		// TODO Autogenerated
		System.out.println(autoInsurance.play());
		textInfo.setText("姓名：" + textFieldName.getText() + '\n' + "学号：" + textFieldNum.getText() + '\n' + "保险类型：" + autoInsurance.play());
	}

	@Override
	public void initialize(URL arg0, ResourceBundle arg1) {
		
		image = new Image("/cn/edu/scau/cmi/linpeiwei/view/0703213803.jpg");
		imageView.setImage(image);
		choiceBox1.getItems().addAll(FXCollections.observableArrayList("PICC","PingAn"));
		//choiceBox.getSelectionModel().selectFirst();
		choiceBox1.getSelectionModel().selectedIndexProperty().addListener((ov,oldv,newv)->{
			abstractFactory = AbstractFactory.getFactory(company[newv.intValue()]);
			infoButton.setDisable(true);
		});
		
		choiceBox2.getItems().addAll(FXCollections.observableArrayList(insurance));
		//choiceBox.getSelectionModel().selectFirst();
		choiceBox2.getSelectionModel().selectedIndexProperty().addListener((ov,oldv,newv)->{
			switch (newv.intValue()) {
			case 0:
				autoInsurance = abstractFactory.createPersonInjur();
				break;
			case 1:
				autoInsurance = abstractFactory.createColission();
				break;
			case 2:
				autoInsurance = abstractFactory.createBodyInjur();
				break;
			case 3:
				autoInsurance = abstractFactory.createCom();
				break;
			}
			infoButton.setDisable(false);
		});
		
	}
}
